package com.xiaoxiong.mami.dao.mapper;

import com.xiaoxiong.mami.dao.daomain.OrderGoods;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface OrderGoodsMapper {
    @Delete({
        "delete from order_goods",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into order_goods (id, orderId, ",
        "goodsTitle, goodsId, ",
        "goodsPrice, thumbUrl, ",
        "total, goodsNumber, ",
        "propertyId, propertyName, ",
        "createTime)",
        "values (#{id,jdbcType=BIGINT}, #{orderId,jdbcType=VARCHAR}, ",
        "#{goodsTitle,jdbcType=VARCHAR}, #{goodsId,jdbcType=VARCHAR}, ",
        "#{goodsPrice,jdbcType=DOUBLE}, #{thumbUrl,jdbcType=VARCHAR}, ",
        "#{total,jdbcType=INTEGER}, #{goodsNumber,jdbcType=VARCHAR}, ",
        "#{propertyId,jdbcType=INTEGER}, #{propertyName,jdbcType=VARCHAR}, ",
        "#{createTime,jdbcType=TIMESTAMP})"
    })
    int insert(OrderGoods record);

    @InsertProvider(type=OrderGoodsSqlProvider.class, method="insertSelective")
    int insertSelective(OrderGoods record);

    @Select({
        "select",
        "id, orderId, goodsTitle, goodsId, goodsPrice, thumbUrl, total, goodsNumber, ",
        "propertyId, propertyName, createTime",
        "from order_goods",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="orderId", property="orderId", jdbcType=JdbcType.VARCHAR),
        @Result(column="goodsTitle", property="goodsTitle", jdbcType=JdbcType.VARCHAR),
        @Result(column="goodsId", property="goodsId", jdbcType=JdbcType.VARCHAR),
        @Result(column="goodsPrice", property="goodsPrice", jdbcType=JdbcType.DOUBLE),
        @Result(column="thumbUrl", property="thumbUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="total", property="total", jdbcType=JdbcType.INTEGER),
        @Result(column="goodsNumber", property="goodsNumber", jdbcType=JdbcType.VARCHAR),
        @Result(column="propertyId", property="propertyId", jdbcType=JdbcType.INTEGER),
        @Result(column="propertyName", property="propertyName", jdbcType=JdbcType.VARCHAR),
        @Result(column="createTime", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    OrderGoods selectByPrimaryKey(Long id);

    @UpdateProvider(type=OrderGoodsSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(OrderGoods record);

    @Update({
        "update order_goods",
        "set orderId = #{orderId,jdbcType=VARCHAR},",
          "goodsTitle = #{goodsTitle,jdbcType=VARCHAR},",
          "goodsId = #{goodsId,jdbcType=VARCHAR},",
          "goodsPrice = #{goodsPrice,jdbcType=DOUBLE},",
          "thumbUrl = #{thumbUrl,jdbcType=VARCHAR},",
          "total = #{total,jdbcType=INTEGER},",
          "goodsNumber = #{goodsNumber,jdbcType=VARCHAR},",
          "propertyId = #{propertyId,jdbcType=INTEGER},",
          "propertyName = #{propertyName,jdbcType=VARCHAR},",
          "createTime = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(OrderGoods record);
}